package com.hasbei.service.impl;

import com.hasbei.dao.ITopicDao;
import com.hasbei.service.ITopicService;
import com.hasbei.vo.TopicVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class TopicServiceImpl implements ITopicService {

    @Resource
    private ITopicDao iTopicDao;

    @Override
    @Cacheable(value = "hesbei:topic",key = "#root.methodName")
    public List<TopicVO> findTopicList() {
        return iTopicDao.findTopicList();
    }

    @Override
    @Cacheable(value = "hesbei:topic",key = "#root.methodName")
    public List<TopicVO> findConsultTopicList() {
        return iTopicDao.findTopicListInfo("zx");
    }

    @Override
    @Cacheable(value = "hesbei:topic",key = "#root.methodName")
    public List<TopicVO> findIssueTopicList() {
        return iTopicDao.findTopicListInfo("m");
    }

    @Override
    @Cacheable(value = "hesbei:topic",key = "#root.methodName+#id")
    public TopicVO findTopicById(long id) {
        return iTopicDao.findTopicById(id);
    }


    @Override
    @CacheEvict(value="hesbei:topic", allEntries=true)
    public int addTopic(TopicVO topicVO) {
        iTopicDao.addTopic(topicVO);
        return 1;
    }

    @Override
    @CacheEvict(value="hesbei:topic", allEntries=true)
    public int delTopic(long id) {
        iTopicDao.delTopic(id);
        return 1;
    }

    @Override
    @CacheEvict(value="hesbei:topic", allEntries=true)
    public int alterTopic(TopicVO topicVO) {
        iTopicDao.alterTopic(topicVO);
        return 1;
    }

    @Override
    public List<TopicVO> findConsultTopicList() {
        return iTopicDao.findTopicListInfo("zx");
    }

    @Override
    public List<TopicVO> findIssueTopicList() {
        return iTopicDao.findTopicListInfo("m");
    }
}
